import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import defaultLayout from '@/layout/defaultLayout.vue'
import aLayout from '@/layout/aLayout.vue';
import leftrightLyaout from '@/layout/leftrightLyaout.vue';
const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        component: defaultLayout,
        children: [
            {
                path:'',
                name: 'Home',
                component: () => import('@/views/Home.vue')
            }
        ]
    },
    {
        path: '/more',
        component: aLayout,
        children: [
            {
                path:'',
                name: 'moreDetail',
                component: () => import('@/views/moreDetail.vue')
            },
            {
                path:'fabu',
                name: 'fabu',
                component: () => import('@/views/fabu.vue')
            },
            {
                path:'chanp',
                name: 'chanp',
                component: () => import('@/views/chanp.vue')
            },
            {
                path: 'case',
                name: 'case',
                component: () => import('@/views/case.vue')
            },
            {
                path: 'news',
                name: 'news',
                component: () => import('@/views/news.vue')
            },
            {
                path: 'chanpfb',
                name: 'chanpfb',
                component: () => import('@/views/chanpfabu.vue')
            },
            {
                path: 'huoban',
                name: 'huoban',
                component: () => import('@/views/huoban.vue')
            },
            {
                path: 'morenews',
                name: 'morenews',
                component: () => import('@/views/morenews.vue')
            }
        ]
    },
]

const router = createRouter({
    history: createWebHistory(),
    routes,
    scrollBehavior(to, from, savedPosition) {
        if (to.hash) {
            const header = document.querySelector('.header'); // 根据实际头部选择器调整
            const offsetY = header ? header.offsetHeight : 0;
            return {
                el: to.hash,
                offset: { y: offsetY }, // ✅ 动态计算偏移
                behavior: 'smooth'
            };
        }
        return { top: 0 };
    }
});

export default router;
